<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item
              label="回程出发时间"
            >
              <a-date-picker v-model="postParams.qpsj"/>
            </a-form-item>
          </a-col>

            <a-col :md="6" :sm="12">
              <a-form-item
                label="到达日期"
              >
               <a-date-picker v-model="postParams.ddsj"/>
              </a-form-item>
            </a-col>

              <a-col :md="6" :sm="12">
              <a-form-item
                label="申报项目名称"
              >
               <a-select v-model="queryParam.gjhxmsbId" :allowClear="true" showSearch optionFilterProp="children">
              <a-select-option :key="i.id" :value="i.id" v-for="i in selectMenu.xmmc">{{ i.projectName }}</a-select-option>
            </a-select>
              </a-form-item>
            </a-col>

          <a-col :md="6" :sm="12">
            <a-form-item
              label="回程出发地"
            >
              <a-input v-model="queryParam.cfd"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="16">
            <span class="table-page-search-submitButtons">
                <!-- <a-button type="primary" @click="addReport" style="margin:0 10px">{{ $t('btn.add') }}</a-button> -->
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">查询</a-button>
              <a-button style="margin: 0 10px" @click="() => queryParam = {}">重置</a-button>
              <a-button type="primary" style="margin: 0 10px" @click="exportThis">导出</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        ref="table"
        size="default"
        rowKey="index"
        :columns="columns"
        :data="loadData"
        :alert="{show: false}"
        :pagination="{ pageSize: 10 }"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>

        <template slot="operation" slot-scope="text, record">
            <a @click="showDetail(record.id)"> 查看详情 </a>
            <a v-hasPermission="'hxsqsh:zzje'" v-if="record.xmsbId==2 || record.xmsbId==3 || record.xmsbId==4 || record.xmsbId==5 " @click="detailThis(record)"> 资助金额 </a>
            <a v-hasPermission="'hxsqsh:xg'"  @click="edit(record,record.id)"> 修改 </a>
          <!-- <a  @click="editThis(record.id)">{{ $t('key.xg') }}</a>
           <a  @click="delThis(record.id)">{{ $t('key.delete') }}</a> -->
        </template>
      </s-table>
      <report-edit ref="testManageEdit" @close="handleEditClose" @success="handleEditSuccess" :info="reportInfo"  :recruitEditVisiable="reportVisible"></report-edit>
    </a-card>

    <check-modal
      ref="check"
      :visible="visible"
      :info ='rptInfo'
      @cancel="cancelThis"
      @refresh="$refs.table.refresh(true)"
    />
  </div>

</template>

<script>
  import {STable} from '~'
  import checkModal from './checkModal'
  import moment from 'moment'
  import reportEdit from './reportEdit'
  // import { delete } from 'vue/types/umd'

export default {
  name: 'report-review',
  data() {
    return {
      advanced: true,
      visible: false,
      rptInfo:{},
      postParams:{},
      queryParam: {},
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '姓名',
          dataIndex: 'xsxx.xm'
        },
        {
          title: '院系',
          dataIndex: 'xsxx.xjxx.ssyxmc'
        },
        {
          title: '专业',
          dataIndex: 'xsxx.xjxx.sszymc'
        },
        {
          title: '学生类别',
          dataIndex: 'xsxx.xjxx.pyccmc'
        },
        {
          title: '导师姓名',
          dataIndex: 'xsxx.xjxx.dsxm'
        },
        {
          title: '项目名称',
          dataIndex: 'projectName'
        },
        {
          title: '回程出发时间',
          dataIndex: 'cfDate'
        },
        {
          title: '回程出发地',
          dataIndex: 'cfd'
        },

        {
          title: '到达日期',
          dataIndex: 'ddDate'
        },
        {
          title: '操作',
          dataIndex: 'option',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      loadData: parameter => {
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        if(this.postParams.qpsj){
            params.cfdate = this.postParams.qpsj.format('YYYY-MM-DD');
        }else{
            delete params.cfdate
        }
        if(this.postParams.ddsj){
            params.dddate = this.postParams.ddsj.format('YYYY-MM-DD');
        }else {
            delete params.dddate
        }
        return this.$api.student.reportList(params).then(res => {
            res.data.rows.map(item =>{
                if(item.cfDate)item.cfDate=moment(item.cfDate).format('YYYY-MM-DD')
                if(item.ddDate)item.ddDate=moment(item.ddDate).format('YYYY-MM-DD')
            })
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {
        xmmc:[]
      },
      reportInfo:{},
      reportVisible:false
    }
  },
  components: { STable,reportEdit,checkModal },
//   computed: {
//     ...mapState({
//       TYPE0075: state => state.app['TYPE0075'], // 学生类别
//       TYPE0126: state => state.app['TYPE0126'], // 年级
//     })
//   },
  created () {
    this.initSelectMenu()
  },
  methods: {
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    initSelectMenu () {
      let allRequest = [
        this.$api.student.reportBasic(),
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          xmmc: res[0].data.xmsb
        }
      })
    },
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zy', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zy', [])
      }
    },
    showDetail(id){
      this.visible = true
      this.$api.student.reportDetile(id).then(res => {
        this.rptInfo = res.data
        this.$refs.check.type = 'detail'
      })
    },
    cancelThis(){
        this.visible = false;
        this.$refs.check.form.resetFields()
    },
    detailThis(val){
      this.reportVisible = true
      this.reportInfo = val
    },
    edit(val,id){
      this.$api.student.reportDetile(id).then(res => {
        this.visible = true
        this.rptInfo = val
        this.rptInfo.coursewareList = res.data.coursewareList
        this.rptInfo.edit = true
      })
      
    },
    exportThis(){
         if(this.postParams.qpsj){
            this.queryParam.cfdate = this.postParams.qpsj.format('YYYY-MM-DD');
        }
        if(this.postParams.ddsj){
            this.queryParam.dddate = this.postParams.ddsj.format('YYYY-MM-DD');
        }
        this.$export('admissions/gjhxbd/export',this.queryParam)
    },
    handleEditClose(){
      this.reportVisible = false
    },
    handleEditSuccess(){

    }
  }
}
</script>
